package com.apes.crm.vip.masterdata.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 账户类型表
 *
 * @author wuq
 * @create 2018-10-09 13:58
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = AccountType.CONST_TABLE_NAME)
public class AccountType extends Model {
    public static final String CONST_TABLE_NAME = "crm_account_type";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "账户编码", prefix = "8")
    private String id;

    @Column(name = "name", length = 64, nullable = false)
    private String name; //账户名称

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "account_category", referencedColumnName = "id")
    private Enumeration accountCategory; //账户类别：( balance:余额; redPackets:红包; voucher:兑换券;)

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "account_type", referencedColumnName = "id")
    private Enumeration accountType; //账户类型：( money:金额类; number:数量类;)

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "valid_date_start")
    private Date validDateStart; //有效期起

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "valid_date_end")
    private Date validDateEnd; //有效期止

    @Column(name = "manage_valid_date", nullable = false, columnDefinition = "number(1,0) default 0")
    private boolean manageValidDate = false; //是否管理有效期

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "valid_date_rule", referencedColumnName = "id")
    private Enumeration validDateRule;      // 有效期规则

    @Column(name = "defer_day", columnDefinition = "number(3,0) default 0")
    private int deferDay;   // 递延天数

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "fix_date")
    private Date fixDate; //固定日期

    @Column(name = "valid_day", columnDefinition = "number(3,0) default 0")
    private int validDay;   // 有效天数
}
